var util = require("../../utils/util.js"),
  app = getApp();

Page({
  data: {
    users: !0,
    level_name: "初始会员",
    score: 0
  },
  onLoad: function(e) {home
    var t = this;
    // 头部样式
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    });
    app.util.request({
      url: "entry/wxapp/GetSystem",
      cachetime: "0",
      success: function(e) {
        console.log(e), wx.setStorageSync("platform", e.data), wx.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#ffffff'
        }), wx.setNavigationBarTitle({
          title: e.data.pt_name
        }), t.setData({
          platform: e.data,
          color: e.data.color,
          grade: e.data.open_member
        });
      }
    });
    var n = wx.getStorageSync("url");
    t.setData({
      url: n
    });
  },
  bind_user_info: function(e) {
    var n = this;
    app.getUserInfo(function(e) {
      console.log(e);
      if (e.name == '' && e.img == '') console.log("这是没有检测到授权"), n.setData({
        users: true,
        level_name: "初始会员",
        userInfo: [],
        score: 0
      });
      else {
        if (n.setData({
            users: true
          }), 0 == e.level_id) var t = "初始会员";
        else t = e.level_name;
        n.setData({
          level_name: t,
          score: e.score,
          userInfo: e
        });
      }
    });
  },
  bindgetuserinfo: function (t) {
    var e = this;
    console.log(t);
    if ("getUserInfo:fail auth deny" == t.detail.errMsg) {
      console.log(e.data.userinfo)
      wx.showModal({
        title: "",
        content: "您拒绝了个人信息授权，无法正常使用小程序"
      });
      return false;
    }
    e.bind_user_info();
  },
  formSubmit: function (t) {
    var e = this;
    console.log(t);
    var a = t.detail.formId,
      o = e.data.grade,
      n = e.data.users;
    console.log(n);
    if ("" == n.img) e.setData({
      user_info: !0
    }), app.getUserInfo(function (t) { });
    else if (n.tel == '') {
      wx.showModal({
        content: "请先绑定手机号",
        success: function (t) {
          t.confirm && (console.log("用户点击确定"), wx.navigateTo({
            url: "../register/register"
          }));
        }
      });
    } else {
      // 授权成功
      
    }
  },
  user: function(e) {
    var n = this;
    app.getUserInfo(function(e) {
      console.log(e);
      if (0 == e.level_id) var t = "初始会员";
      else t = e.level_name;
      console.log(t), n.setData({
        level_name: t,
        score: e.score,
        userInfo: e
      });
    });
  },
  my_interests () {
    // 我的权益卡
    wx.navigateTo({
      url: './../interests/interests_list',
    })
  },
  refresh: function(e) {
    var t = this,
      n = getCurrentPages(),
      o = n[n.length - 1],
      a = n[n.length - 2];
    console.log(n), console.log(o), console.log(a);
    var s = wx.getStorageSync("userInfo").id;
    app.util.request({
      url: "entry/wxapp/CheckRz",
      data: {
        user_id: s
      },
      success: function(e) {
        console.log(e), t.setData({
          state: e.data
        });
      }
    }), app.util.request({
      url: "entry/wxapp/GetFxSet",
      success: function(e) {
        console.log(e), t.setData({
          GetFxSet: e.data
        });
      }
    });
  },
  mine_order: function(e) {
    if (1 == this.data.users) {
      var t = e.currentTarget.dataset.index,
        n = t;
      console.log(t), wx.navigateTo({
        url: "../order/order?activeIndex=" + n + "&index=" + t,
        success: function(e) {},
        fail: function(e) {},
        complete: function(e) {}
      });
    } else this.bind_user_info();
  },
  home: function(e) {
    wx.reLaunch({
      url: "../index/index_c"
    });
  },
  evaluate: function() {
    wx.navigateTo({
      url: './evaluate'
    })
  },
  seller_manage: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../login_entry/login_entry"
    }) : this.bind_user_info();
  },
  opensetting: function(e) {
    wx.openSetting({});
  },
  integral: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../jifen/jifen"
    }) : this.bind_user_info();
  },
  settled_store: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../settled_store/settled_store"
    }) : this.bind_user_info();
  },
  service: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../service/service"
    }) : this.bind_user_info();
  },
  coupon: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../coupon/store_coupon"
    }) : this.bind_user_info();
  },
  my_tickets: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../coupon/my_tickets"
    }) : this.bind_user_info();
  },
  receive_coupon: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../coupon/receive_coupon"
    }) : this.bind_user_info();
  },
  user_zhuce: function(e) {
    var t = this.data,
      n = t.userInfo,
      o = t.grade;
    console.log(o), 1 == o && null != o ? (console.log("可以注册"), "" == n.zs_name || null == n.zs_name ? (console.log("检测到用户尚未注册会员"),
      wx.navigateTo({
        url: "../register/register"
      })) : (console.log("检测到用户已经注册会员"), wx.navigateTo({
      url: "member"
    }))) : wx.navigateTo({
      url: "member"
    });
  },
  cancel_storange: function(e) {
    wx.clearStorage(), wx.showToast({
      title: "清除成功"
    });
  },
  copyright: function(e) {
    var t = wx.getStorageSync("platform").tz_appid;
    wx.navigateToMiniProgram({
      appId: t,
      success: function(e) {
        console.log(e);
      }
    });
  },
  recharge: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../recharge/index"
    }) : this.bind_user_info();
  },
  score_detail: function(e) {
    1 == this.data.users ? wx.navigateTo({
      url: "../jifen/scoredetails"
    }) : this.bind_user_info();
  },
  distribution: function(e) {
    var t = this;
    if (1 == t.data.users) {
      var n = t.data.GetFxSet;
      console.log(n);
      var o = t.data.userInfo,
        a = wx.getStorageSync("userInfo").id,
        s = t.data.grade;
      "" == o.zs_name && 1 == s ? wx.showModal({
        content: "请先绑定手机号",
        success: function(e) {
          e.confirm && (console.log("用户点击确定"), wx.navigateTo({
            url: "../register/register"
          }));
        }
      }) : app.util.request({
        url: "entry/wxapp/MyDistribution",
        data: {
          user_id: a
        },
        success: function(e) {
          console.log(e), 0 == e.data ? wx.navigateTo({
            url: "../distribution/examine"
          }) : 1 == e.data.state ? wx.showModal({
            title: "温馨提示",
            content: "系统正在审核中，请稍后再试"
          }) : 2 == e.data.state ? wx.navigateTo({
            url: "../distribution/distribution"
          }) : 3 == e.data.state && wx.showModal({
            title: "温馨提示",
            content: "您的申请已被拒绝"
          });
        }
      });
    } else t.bind_user_info();
  },
  bindGetUserInfo: function(e) {
    var t = this;
    e.detail.userInfo;
    app.getUserInfo(function(e) {
      t.bind_user_info();
    });
  },
  onReady: function() {},
  onShow: function() {
    this.refresh(), this.bind_user_info();
    // 头部样式
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    });
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {}
});